{% extends "layouts/main.html" %}
{% set pageTitle = "爬虫管理" %}
{% set pageDesc = "×" %}

{% block content %}
<div class="box">
    <div class="box-header">
        <h3 class="box-title">爬虫列表</h3>
        <div class="box-tools">
            {# <a href="{{ url_for('main.spider_manager', command='run_all', _external=True) }}"
               class="btn btn-primary">运行爬虫</a>
            #}
            <a href="{{ url_for('main.spider_manager', command='index_all', _external=True) }}"
               class="btn btn-primary">刷新索引</a>
        </div>
    </div>
    <!-- /.box-header -->
    <div class="box-body">
        <div id="example2_wrapper" class="dataTables_wrapper form-inline dt-bootstrap">
            <div class="row">
                <div class="col-sm-6"></div>
                <div class="col-sm-6"></div>
            </div>
            <div class="row">
                <div class="col-sm-12">
                    <table id="example2" class="table table-bordered table-hover dataTable" role="grid"
                           aria-describedby="example2_info">
                        <thead>
                        <tr role="row">
                            <th>#</th>
                            <th>爬虫名</th>
                            <th>目标站</th>
                            <th>捉取信息总数</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>

                                {% if not spiders %}
                                    <tr><td colspan="5">暂无数据</td></tr>
                                {% endif %}
                                {% for spider in spiders %}
                                <tr class="{{ loop.cycle('odd', 'even') }}">
                                    <td>{{ loop.index }}</td>
                                    <td>{{ spider.name }}</td>
                                    <td>
                                        {% if spider.source %}
                                            <a href="{{ spider.source.url }}" target="_blank">{{ spider.source.title }}</a>
                                        {% else %}
                                            None
                                        {% endif %}
                                    </td>
                                    <td>{{ spider.source.jobs.count() if spider.source else 0 }}</td>
                                    <td>{{ spider.status }}</td>
                                    <td>
                                        {% if spider.status == 'running' %}
                                            <a href="{{ url_for('main.spider_manager', command='stop', s=spider.name, id=spider.id, _external=True) }}"
                                                title="停止"><i class="fa fa-stop"></i></a>
                                        {% else %}
                                            <a href="{{ url_for('main.spider_manager', command='run', s=spider.name, _external=True) }}"
                                                title="运行"><i class="fa fa-play"></i></a> &nbsp;&nbsp;
                                        {% endif %}
                                    </td>
                                </tr>
                                {% endfor %}
                        </tbody>
                        <tfoot>
                            <tr role="row">
                                <th>#</th>
                                <th>爬虫名</th>
                                <th>目标站</th>
                                <th>捉取信息总数</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <!-- /.box-body -->
</div>
{% endblock %}